package org.example.graphql;

import cn.hutool.core.io.FileUtil;
//import graphql.ExecutionResult;
//import graphql.GraphQL;
//import graphql.schema.GraphQLSchema;
//import graphql.schema.StaticDataFetcher;
//import graphql.schema.idl.*;

public class GraphqlDemo {
//    public static void main(String[] args) {
//        hero();
//    }
//
//    static void hero() {
//        exe("Hero",
//                builder -> builder.dataFetcher("name", new StaticDataFetcher("maria"))
//                        .dataFetcher("age", new StaticDataFetcher(12))
//                        .dataFetcher("appearsIn", new StaticDataFetcher(new String[] {"NEWHOPE"}))
//                );
//    }
//
//    static void hello() {
//        exe("HelloWorld",
//                builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))
//                .dataFetcher("version",new StaticDataFetcher("1.0"))
//        );
//    }
//
//    @FunctionalInterface
//    interface BuildData{
//        TypeRuntimeWiring.Builder data(TypeRuntimeWiring.Builder builder);
//    }
//
//    static void exe(String schema, BuildData buildData) {
//        SchemaParser schemaParser = new SchemaParser();
//        TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(FileUtil.file("graphql/schema/"+schema + ".graphqls"));
//        RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
//                .type(schema, builder -> buildData.data(builder))
//                .build();
//        SchemaGenerator schemaGenerator = new SchemaGenerator();
//        GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
//
//        GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
//        ExecutionResult executionResult = build.execute(FileUtil.readUtf8String(FileUtil.file("graphql/query/"+schema + ".graphqls")));
//
//        System.out.println(executionResult.getData().toString());
//    }

}
